#!/bin/bash
########## cffr investment 开发-- 测试版本部署脚本 
date_stamp=`date "+%Y-%m-%d %H:%M:%S"`
date1=`date "+%Y-%m-%d-%H-%M-%S"`
echo "123+123" 
#jar地址
SERVCER_JAR=earning-farm-investment-0.0.1-SNAPSHOT.jar
#日志名称
LOG_NAME=cff-investment.log
#进入对应目录
DIR="/home/ubuntu/cff-investment"
#输出信息
echo '---------------------------------------'
echo $DIR
#创建项目jar包工程目录
if [ ! -d $DIR/jar ];then
  mkdir -p $DIR/jar
fi
#创建备份目录
echo $date_stamp
echo $SERVCER_JAR

cp $DIR/$SERVCER_JAR  $DIR/jar3
cp $DIR/$SERVCER_JAR  $DIR/jar4
cp $DIR/$SERVCER_JAR  $DIR/jar5

#高风险investment  jar6 jar7

cp $DIR/$SERVCER_JAR  $DIR/jar6
cp $DIR/$SERVCER_JAR  $DIR/jar7

export branch_v=$1
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_311
export JAVA=$JAVA_HOME/bin/java
export PATH=${JAVA_HOME}/bin:$PATH
echo "$branch_v "
echo '---------------------------------------java path'
source /home/ubuntu/cff-investment/.env

case  $2 in
  "musdc" )
          _pid3=`ps -ef | grep java | grep jar3/$SERVCER_JAR |awk '{print $2}'`
          echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
          [ -n "$_pid3" ] && kill -9 $_pid3
          sleep 5
          echo "musdc"
          nohup  java -jar \
          -Xms256m -Xmx256m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/musdc/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=USDC \
          -Dserver.port=8680 \
          -Dsubscription.service.url=10.10.10.72:8180 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/usdc \
          -Dnet_work=mainnet  \
          -Dorigin_ration=1000000 \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_musdc?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/musdc  \
          -Dserver.address=10.10.10.72 \
          $DIR/jar3/$SERVCER_JAR  >>$DIR/logs/musdc/$LOG_NAME  2>&1  &

          sleep 5
          ;;
  "meth" )
        _pid4=`ps -ef | grep java | grep jar4/$SERVCER_JAR |awk '{print $2}'`
        echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
        [ -n "$_pid4" ] && kill -9 $_pid4
        sleep 5
        echo "meth"
        nohup  java -jar \
          -Xms256m -Xmx256m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/meth/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=ETH \
          -Dserver.port=8780 \
          -Dsubscription.service.url=10.10.10.72:8180 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/eth \
          -Dnet_work=mainnet \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_meth?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/meth  \
          -Dserver.address=10.10.10.72 \
          $DIR/jar4/$SERVCER_JAR  >>$DIR/logs/meth/$LOG_NAME  2>&1  &
          sleep 5
          ;;
  "mwbtc" )
        _pid5=`ps -ef | grep java | grep jar5/$SERVCER_JAR |awk '{print $2}'`
        echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
        [ -n "$_pid5" ] && kill -9 $_pid5
        sleep 5
        echo "mwbtc"
        nohup  java -jar \
          -Xms256m -Xmx256m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/wbtc/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=WBTC \
          -Dserver.port=8880 \
          -Dsubscription.service.url=10.10.10.72:8180 \
          -Dspring.datasource.username=$investment_name -Dspring.datasource.password=$investment_passwd \
          -Drisk_type=0   \
          -Dserver.servlet.context-path=/wbtc \
          -Dnet_work=mainnet  \
          -Dorigin_ration=100000000 \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_mwbtc?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/wbtc  \
          -Dserver.address=10.10.10.72 \
          $DIR/jar5/$SERVCER_JAR  >>$DIR/logs/wbtc/$LOG_NAME  2>&1  &
          ;;
  "husdc" )
        _pid6=`ps -ef | grep java | grep jar6/$SERVCER_JAR |awk '{print $2}'`
        echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
        [ -n "$_pid6" ] && kill -9 $_pid6
        echo "  husdc"
        nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC  -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps      \
          -Dspring.profiles.active=prod   \
          -Dserver.port=8280  \
          -Dcff-name=USDC         \
          -Dsubscription.service.url=10.10.10.72:8180    \
          -Drisk_type=1     \
          -Dvalue_type=1          \
          -Dserver.servlet.context-path=/husdc    \
          -Dnet_work=ropsten     \
          -Dspring.datasource.username=test-investment4 -Dspring.datasource.password='test-cff@!@#YeeZ'     \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_husdc?useUnicode=true&characterEncoding=utf-8"     \
          -Dlogging.file.path=/home/ubuntu/cff-investment  \
          -Dserver.address=10.10.10.72    \
          /home/ubuntu/cff-investment/jar6/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/husdc/cff-investment.log  2>&1  &
          sleep 5
          ;;
  "heth"  )
          _pid7=`ps -ef | grep java | grep jar7/$SERVCER_JAR |awk '{print $2}'`
          echo "kill ------>"$SERVCER_JAR "pid---->" $_pid
          [ -n "$_pid7" ] && kill -9 $_pid7
          sleep 5
      echo " heth"
      nohup java -jar -Xms128m -Xmx128m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC -Xloggc:/home/ubuntu/cff-investment/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps        \
        -Dspring.profiles.active="prod" \
        -Dcff_name=ETH  \
        -Dserver.port=8580  \
        -Dsubscription.service.url=10.10.10.72:8180     \
        -Drisk_type=1  \
        -Dfee_ratio=0.025   \
        -Dserver.servlet.context-path=/heth   \
        -Dnet_work=ropsten   \
        -Dorigin_ration=1000000 \
        -Dspring.datasource.username=test-investment4 -Dspring.datasource.password='test-cff@!@#YeeZ'      \
        -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_heth?useUnicode=true&characterEncoding=utf-8"     \
        -Dlogging.file.path=/home/ubuntu/cff-investment       \
        -Dserver.address=10.10.10.72       \
        /home/ubuntu/cff-investment/jar7/earning-farm-investment-0.0.1-SNAPSHOT.jar  >>/home/ubuntu/cff-investment/logs/heth/cff-investment.log  2>&1  &

        sleep 5
        ;;


esac

###################################################################   注释     ######################
<<comment
echo "mhusdc"
nohup  java -jar \
          -Xms256m -Xmx256m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/mhusdc/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=USDC \
          -Dserver.port=8280 \
          -Dsubscription.service.url=10.10.10.72:8180 \
          -Dspring.datasource.username=$investment_name_3 -Dspring.datasource.password=$investment_passwd_3 \
          -Drisk_type=1   \
          -Dvalue_type=1 \
          -Dserver.servlet.context-path=/mhusdc \
          -Dnet_work=mainnet  \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_mhusdc?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/mhusdc  \
          -Dserver.address=10.10.10.72 \
          $DIR/jar6/$SERVCER_JAR  >>$DIR/logs/mhusdc/$LOG_NAME  2>&1  &

echo "mheth"
ls ~/cff-investment/jar7/
nohup  java -jar \
          -Xms256m -Xmx256m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128M -XX:+UseG1GC \
          -Xloggc:$DIR/logs/mheth/gc.log  -XX:+PrintGCDetails -XX:+PrintGCTimeStamps \
          -Dspring.profiles.active="prod" \
          -Dcff_name=ETH \
          -Dserver.port=8380 \
          -Dsubscription.service.url=10.10.10.72:8180 \
          -Dspring.datasource.username=$investment_name_4 -Dspring.datasource.password=$investment_passwd_4 \
          -Drisk_type=1   \
	  -Dfee_ratio=0.025  \
          -Dserver.servlet.context-path=/mheth \
          -Dnet_work=mainnet  \
          -Dorigin_ration=1000000 \
          -Dspring.datasource.url="jdbc:mysql://10.10.10.72:3307/earningfarm_mheth?useUnicode=true&characterEncoding=utf-8" \
          -Dlogging.file.path=/home/ubuntu/cff-investment/logs/mheth  \
          -Dserver.address=10.10.10.72 \
          $DIR/jar7/$SERVCER_JAR  >>$DIR/logs/mheth/$LOG_NAME  2>&1  &

comment
###########################2022-06-14 deploy###############################


s_pid=`ps -ef | grep java | grep $SERVCER_JAR |awk '{print $2}'`
send_weixin_v2  "【部署推送】\n【$date_stamp】\n【cff/earning-farm】\n【investment/后端/$2】\n【开发环境】【dev-cff/10.10.10.72】\n【$branch_v】 分支部署完成, 进程pid：$s_pid ,from  部署脚本。 "

